﻿using System;
using System.Text;

/*
 * Write a program that reads a string from the console and replaces all series
 * of consecutive identical letters with a single one.
 * Example: "aaaaabbbbbcdddeeeedssaa" -> "abcdedsa".
 */

namespace IdenticalLetters
{
    class IdenticalLetters
    {
        static void PrintResult(string text)
        {
            foreach (char character in text)
            {
                Console.Write(character);
            }
            Console.WriteLine();
        }

        static string SkipIdenticalLetters(string text)
        {
            StringBuilder result = new StringBuilder();
            char lastChar = text[0];
            result.Append(lastChar);

            for (int index = 1, length = text.Length; index < length; index++)
            {
                if (lastChar != text[index])
                {
                    lastChar = text[index];
                    result.Append(lastChar);
                }
            }

            return result.ToString();
        }

        static void Main()
        {
            string result = SkipIdenticalLetters("aaaaabbbbbcdddeeeedssaa");

            PrintResult(result);
        }
    }
}
